package demo1;

import java.util.Arrays;

/**
 * @Author liangzai
 * @Description:
 */
public class Training {
    //检查棋盘颜色是否相同
    public boolean checkTwoChessboards(String coordinate1, String coordinate2) {
        int a = 0;int b = 0;
        if(((coordinate1.charAt(0)-96)%2==0 && (coordinate1.charAt(1)-32)%2==0) || ((coordinate1.charAt(0)-96)%2==1 && (coordinate1.charAt(1)-32)%2==1)){
            a = 1;
        }
        if(((coordinate2.charAt(0)-96)%2==0 && (coordinate2.charAt(1)-32)%2==0) || ((coordinate2.charAt(0)-96)%2==1 && (coordinate2.charAt(1)-32)%2==1)){
            b = 1;
        }
        return a==b;
    }

    //优势洗牌
    public int[] advantageCount(int[] nums1, int[] nums2) {
        int m = nums1.length;
        Integer[] index = new Integer[m];
        for (int i = 0; i < m; i++) index[i] = i;
        Arrays.sort(index, (i, j) -> {
            return nums2[i]-nums2[j];
        });
        Arrays.sort(nums1);
        Arrays.sort(nums2);
        int left = 0; int right = m-1;
        int[] ret = new int[m];
        for (int i = 0; i < m; i++) {
            if(nums1[i]<nums2[left]){
                ret[right--] = nums1[i];
            }else {
                ret[left++] = nums1[i];
            }
        }
        int[] ret1 = new int[m];
        for (int i = 0; i < m; i++) {
            ret1[index[i]] = ret[index[i]];
        }
        return ret1;
    }

    //对身高排序
    public String[] sortPeople(String[] names, int[] heights) {
        int[] index = new int[heights.length];
        for (int i = 0; i < index.length; i++) index[i] = i;
        for (int i = 0; i < heights.length-1; i++) {
            int maxindex = i;
            for (int j = i+1; j < heights.length; j++) {
                if(heights[maxindex]<heights[j]) maxindex = j;
            }
            int tmp = index[maxindex];
            index[maxindex] = index[i];
            index[i] = tmp;
            tmp = heights[maxindex];
            heights[maxindex] = heights[i];
            heights[i] = tmp;
        }
        String[] ret = new String[names.length];
        for (int i = 0; i < names.length; i++) {
            ret[i] = names[index[i]];
        }
        return ret;
    }
}
